<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>一人一本 - 试过才知道</title>
	<link href="../css/productlist.css" rel="stylesheet">
	<link href="../css/inspiritas.css" rel="stylesheet">
	<link href="../css/carousel.css" rel="stylesheet">
	
	<script src="../js/jquery-1.7.1.min.js"></script>
	<script src="../js/jquery.form.js"></script>
	<script src="../js/jquery.json-2.4.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    
	<script>
	$(document).ready(	
		function()
		{
			typeListClick();
			 $.getJSON('?act=order.get_cart_status', function(data){
				 	$('.product_status').text('可购买');
				 	if (!data.success) {
						$('#place_order_submit').addClass("disabled");
						$('#place_order_submit').click(function(){
							});
				 		for (var error in data.msg) {
				 			switch (data.msg[error].type)
				 			{
				 			case 'Stock Out':
								$('#product_status_'+data.msg[error].id).text("存货不足");
								break;
				 			}
				 		}
				 	} else {
						$('#place_order_submit').removeClass("disabled");
						$('#place_order_submit').click(function(){
							$('#place_order').ajaxSubmit({
								dataType:"json",
								success:function(ret){
									if (ret.success)
									{
										alert("订单生成成功");
									}
									else 
									{
										alert("订单生成失败");
									}
									window.top.location.reload();
								}
							});
						});
				 	}
				});
				$.getJSON('../index.php?act=address.get_all_address', function (data) {
					$('#place_order_submit').addClass("disabled");
				    for (var address in data.ret) {
						$('#place_order_submit').removeClass("disabled");
				        var html = '<tr style="font-size:0.8em;">' + '<td>' + 
				        data.ret[address].Address + '</td>' + '<td>' + data.ret[address].Postal + '</td>' + 
				        '<td>' + data.ret[address].Receiver + '</td>' + 
				        '<td align="right">' + data.ret[address].Phone + '</td>' + 
				        '<td><input type="radio" id="address" name="address" class="btn btn-success span8" value="' + data.ret[address].ID + '"/></td>' + '</tr>';
				        $('#address_table').append(html);
					    $('#address').attr('checked','checked');
				    }
				});
			/*$.getJSON('http://localhost/b2c/index.php?act=address.get_default_address', function(data){
						var address = data.ret.Address + " " + data.ret.Postal + " " + data.ret.Receiver + " " + data.ret.Phone;
						$('#default_address').text(address);
					}
				);*/
				{include "order/order/ready.htm"}
		}
	);
	
	function typeListClick()
	{
		$('#manage-list').children(':not(".divider,h3")').click(function(){
			$(this).addClass('active');
			$(this).siblings().removeClass('active');
		});
		$('#user_address').click(function(){
			$('#addressInfo').removeClass("hidden");
			$('#productInfo').addClass("hidden");
		});
		$('#product_list').click(function(){
			$('#addressInfo').addClass("hidden");
			$('#productInfo').removeClass("hidden");
		});
	}

	</script>
</head>
<body>
<div class="container">
{include "order/order/head.htm"}

<div class="row">
	<div id="user_panel" class="span3  user-panel" style="left:60px;">
		<ul  id="manage-list" class="nav nav-list " style="postition:fixed">
			<h3><li class="nav-header" style="font-weight:bold;text-align:right;">订单确认</li></h3>
			<li class="divider"></li>
			<li id="" class="active"><a class="type-link" id="product_list" href="javascript:void(0)">&nbsp;<span style="float:right;">商品列表</span></a></li>
			<li class=""><a class="type-link" id="user_address" href="javascript:void(0)">&nbsp;<span style="float:right;">我的收货地址</span></a></li>
		</ul>
    </div>

	
	<div id="productInfo" class="span9 pull-right">
			  <div class="row-fluid">
				<h1 class="span8 rhine">查看<small>购物车</small></h1>
			  </div>
				</br></br>
			<div>
				<table cellspacing="1" cellpadding="3" class="tablehead table table-paper table-condensed table-striped " style="background:#CCC;">
				<thead>
				<tr>
				<th colspan="6">商品列表</th>
				</tr>
				<tr>
				<th>图片</th>
				<th>商品信息</th>
				<th>原价</th>
				<th>现价</th>
				<th>数量</th>
				<th>状态</th>
				</tr>
				</thead>
				<tbody>
				{foreach from=$product_info item=product}
				<tr>
				<td><img src="../{$product.IMAGE}" class="img-rounded" width="100"></td>
				<td><p><strong>《{$product.Name}》</strong></p><p>{$product.Author}</p></td>
				<td>{$product.Price}</td>
				<td>{$product.current_price}</td>
				<td>{$product.Amount}</td>
				<td><div id="product_status_{$product.ID}" class="product_status"></div></td>
				</tr>
				{/foreach}
				</tbody>
				<tfoot>
				<tr><td>总金额</td><td>￥&nbsp<strong>{$total_price}</strong></td></tr>
				</tfoot>
				</table>
			</div>
	</div>
	
	<div id="addressInfo" class="span9 pull-right hidden">
			<div class="row-fluid">
				<h1 class="span8 rhine">选择<small>收货地址</small></h1>
			</div>
			</br></br>
		<div class="row-fluid">
			<form id="place_order" action="?act=order.place_order" method="post">
			<table cellspacing="1" cellpadding="3" class="tablehead table table-paper table-condensed table-striped " style="background:#CCC;">
					<thead>  
						<tr>
							<th class>地址</th>
							<th class>邮编</th>
							<th class>收件人</th>
							<th class>联系方式</th>
							<th class>选择此地址</th>
						</tr>
					</thead>
					<tbody id="address_table">
					</tbody>
			</table>
			<input id="place_order_submit" class="btn btn-success span2" type="button" value="提交订单">
			</form>
		</div>
	</div>
</div>

{include "order/order/footer.htm"}
</div>

</body>
</html>
